﻿CREATE PROCEDURE [dbo].[yaf_active_stats](
                @BoardID INT)
AS
    BEGIN
        SELECT ActiveUsers = (SELECT COUNT(1)
                              FROM   yaf_Active
                              WHERE  BoardID = @BoardID),
               ActiveMembers = (SELECT COUNT(1)
                                FROM   yaf_Active x
                                WHERE  BoardID = @BoardID
                                AND EXISTS (SELECT 1
                                            FROM   yaf_UserGroup y,
                                                   yaf_Group z
                                            WHERE  y.UserID = x.UserID
                                            AND y.GroupID = z.GroupID
                                            AND (z.Flags & 2) = 0)),
               ActiveGuests = (SELECT COUNT(1)
                               FROM   yaf_Active x
                               WHERE  BoardID = @BoardID
                               AND EXISTS (SELECT 1
                                           FROM   yaf_UserGroup y,
                                                  yaf_Group z
                                           WHERE  y.UserID = x.UserID
                                           AND y.GroupID = z.GroupID
                                           AND (z.Flags & 2) <> 0))
    END


